goog.require("goog.array")
goog.require("goog.dom");
goog.require("goog.dom.classes");
goog.require("goog.dom.Range");
goog.require("goog.events");

(function () {
  var listItems = goog.dom.getElementsByTagNameAndClass("", "char-card");
  
  function onCharViewFocus(e) {
    // TODO: This doesn't work in FF!
    var char = goog.dom.getElementsByTagNameAndClass("",
        "char-selection-target", this)[0];
    selectNodeContents(char);
  }
  
  function selectNodeContents(node) {
    goog.dom.Range.createFromNodeContents(node).select();
  }
  
  goog.array.forEach(listItems, function (item) {
    goog.events.listen(item, "focus", onCharViewFocus);
    goog.events.listen(item, "click", onCharViewFocus);
  });
})();
